package zhieasy.cn.common.strategy;

import com.github.zouchanglin.storage.service.upload.result.ReturnBody;
import org.springframework.stereotype.Component;
import zhieasy.cn.common.utils.ResultVOUtil;
import zhieasy.cn.common.vo.ResultVO;


import java.io.InputStream;
import java.util.HashMap;
import java.util.Random;
import java.util.UUID;

/**
 * @author Dahang
 */
@Component
public class BookMarketPolicy extends QiNiuObjectUpload implements UploadStrategy {
    @Override
    public String uploadOneFile(InputStream inputStream, String objectName) {
        // 路劲前加/book_market/
        String key = "/book_market/" + new Random().ints(50).toString() +"/" + UUID.randomUUID();
        ReturnBody returnBody = qiNiuUploadService.uploadStream(inputStream, key, null);
        //TODO returnBody..
        return objectUrl + key;
    }

    @Override
    public ResultVO getTokenAndUrl() {
        //TODO 这里得要写正确回调路径
        String token = qiNiuAuthService.getTokenCallBack(null);
        String key = "book_market/" + String.valueOf(new Random().nextInt(50)) + "/";
        return ResultVOUtil.success(new HashMap<String, String>(){{
            put("token", token);
            put("key", key);
        }});
    }

    @Override
    public ResultVO getTokenAndUrl(String parentId) {
        //TODO 这里得要写正确回调路径
        //String token = qiNiuAuthService.getTokenCallBack("http://2087p773d1.wicp.vip/book-market/object/callback/"+parentId);
        String token = qiNiuAuthService.getTokenCallBack(null);
        String key = "/book_market/" + String.valueOf(new Random().nextInt(50)) + "/" ;
        return ResultVOUtil.success(new HashMap<String, String>(){{
            put("token", token);
            put("key", key);
            put("articleId",parentId);
        }});
    }
}
